//
//  DHomeViewController.swift
//  Drop
//
//  Created by hushaohua on 2017/11/13.
//  Copyright © 2017年 init. All rights reserved.
//

import UIKit

class DHomeViewController: UITabBarController, UITabBarControllerDelegate {

    init(_ selectIndex:Int) {
        self.todayViewController = DTodayViewController(nibName:nil, bundle:nil);
        self.preferenceViewController = DMoreViewController(nibName:nil, bundle:nil);
        self.todayNavigationController = UINavigationController(rootViewController: self.todayViewController);
        self.preferenceNavigationController = UINavigationController(rootViewController: self.preferenceViewController);
        self.fakeDroppingViewController = UIViewController();
        super.init(nibName: nil, bundle: nil);
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //便利构造器不能直接调用父类的指定构造器，需要调用同类中的其他构造器
//    convenience init(testIndex:Int){
//        self.init(testIndex);
//        self.todayViewController = DTodayViewController();
//        self.moreViewController = DMoreViewController();
//    }
    
    var todayViewController:DTodayViewController;
    var preferenceViewController:DMoreViewController;
    var todayNavigationController:UINavigationController;
    var preferenceNavigationController:UINavigationController;
    var fakeDroppingViewController:UIViewController;//fake
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.setupToday();
        self.setupMore();
        self.setupDropping();
        self.viewControllers = [self.todayNavigationController, self.fakeDroppingViewController, self.preferenceNavigationController];
        self.delegate = self;
    }
    
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        if viewController == self.fakeDroppingViewController {
            return false;
        }else{
            return true;
        }
    }
    
    func setupToday() -> Void {
        let image:UIImage = UIImage(named:"tab_today")!.withRenderingMode(.alwaysTemplate);
        let tabItem:UITabBarItem = UITabBarItem(title: "今天", image: image, tag: 0);
        self.todayNavigationController.title = "今天";
        self.todayNavigationController.tabBarItem = tabItem;
    }
    
    func setupMore() -> Void {
        let image:UIImage = UIImage(named:"tab_more")!.withRenderingMode(.alwaysTemplate);
        let tabItem:UITabBarItem = UITabBarItem(title: "更多", image: image, tag: 0);
        self.preferenceNavigationController.title = "更多";
        self.preferenceNavigationController.tabBarItem = tabItem;
    }
    
    func setupDropping() -> Void {
//        let image:UIImage = UIImage(named:"tab_drop")!.withRenderingMode(.alwaysOriginal);
        let tabItem:UITabBarItem = UITabBarItem(title: nil, image: nil, tag: 0);
        self.fakeDroppingViewController.tabBarItem = tabItem;
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated);
        DDroppingManager.sharedManager().load();
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
